HackerRank The Coin Change Problem
解答
code: python
import math
import os
import random
import re
import sys
#
# Complete the 'getWays' function below.
#
# The function is expected to return a LONG_INTEGER.
# The function accepts following parameters:
# 1. INTEGER n
# 2. LONG_INTEGER_ARRAY c
#
'''
10
2 5 3 6
0 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 2 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 5 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 2 3 1, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4 6 1, 0, 1, 1, 1, 2, 3, 2, 4, 4, 5 '''
def getWays(n, c):
# dpi := Total number of ways to make an amount i for i in range(len(c)):
if __name__ == '__main__':
first_multiple_input = input().rstrip().split()
n = int(first_multiple_input0) m = int(first_multiple_input1) c = list(map(int, input().rstrip().split()))
# Print the number of ways of making change for 'n' units using coins having the values given by 'c'
ways = getWays(n, c)
fptr.write(str(ways) + '\n')
fptr.close()
テーマ
提出
code: python
import math
import os
import random
import re
import sys
#
# Complete the 'getWays' function below.
#
# The function is expected to return a LONG_INTEGER.
# The function accepts following parameters:
# 1. INTEGER n
# 2. LONG_INTEGER_ARRAY c
#
'''
10
2 5 3 6
- sort
- dpij := use c:i and use j numbers -- dp13 = dp12 + c1 = 9,8, dp02 + c1 = 7 '''
def getWays(n, c):
# Write your code here
c.sort()
max_use = math.ceil(n/c0) + 1 dp = [[[]] * max_use for _ in range(len(c))]
for i in range(max_use):
for i in range(len(c)):
for i in range(len(c)):
for j in range(1, max_use):
print(dp)
if __name__ == '__main__':
first_multiple_input = input().rstrip().split()
n = int(first_multiple_input0) m = int(first_multiple_input1) c = list(map(int, input().rstrip().split()))
# Print the number of ways of making change for 'n' units using coins having the values given by 'c'
ways = getWays(n, c)
fptr.write(str(ways) + '\n')
fptr.close()